Skip to content

Improve test coverage to ~100% for @azure/core-lro#38178

Merged
deyaaeldeen merged 37 commits intomainfrom
deyaaeldeen/core-lro-test-coverage
Apr 21, 2026
Merged

Improve test coverage to ~100% for @azure/core-lro#38178
deyaaeldeen merged 37 commits intomainfrom
deyaaeldeen/core-lro-test-coverage

Conversation

@deyaaeldeen
Copy link
Copy Markdown
Member

@deyaaeldeen deyaaeldeen commented Apr 16, 2026

Changes

New test files

  • buildCreatePoller.spec.ts
  • http-operation.spec.ts
  • pollHttpOperation.spec.ts
  • poller-state-guard.spec.ts
  • pollerInternals.spec.ts

Expanded existing tests

  • lro.spec.ts: serialization/restore, submitted(), polling intervals, error states
  • rewriteUrl.spec.ts: undefined URL handling

Test quality improvements

  • Replaced pollCount/setState/check flags with vi.fn() + toHaveBeenCalledTimes()
  • Replaced non-null assertions (operationState!) with optional chaining after guards
  • deepEqual on primitives changed to strictEqual
  • assert.equal(x, undefined) changed to assert.isUndefined(x)
  • .mock.calls.length changed to expect matchers

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Deyaaeldeen Almahallawi and others added 14 commits April 17, 2026 00:09
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Split poller-poller.spec.ts:
- test/public/poller.spec.ts: 12 tests using createTestPoller/createHttpPoller
- test/internal/poller-poller.spec.ts: 7 tests using internal helpers

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Deduplicate makeRawResponse (5 files) and makeState (4 files) into
test/utils/utils.ts. All 347 tests pass with build-test clean.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Move 5 tests that only use createTestPoller (public API) from
test/internal/poller-operation.spec.ts to test/public/poller.spec.ts.
Internal file retains 6 tests that use internal APIs (deserializeState,
pollOperation, initOperation, buildCreatePoller).

All 347 tests pass with build-test clean.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
- poller-poller.spec.ts → buildCreatePoller.spec.ts
- poller-operation.spec.ts → pollerInternals.spec.ts
- http-poller.spec.ts → pollHttpOperation.spec.ts

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@deyaaeldeen deyaaeldeen marked this pull request as ready for review April 17, 2026 19:24
@deyaaeldeen deyaaeldeen requested review from a team and joheredi as code owners April 17, 2026 19:24
Copilot AI review requested due to automatic review settings April 17, 2026 19:24
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR expands the @azure/core-lro test suite with additional internal and public tests to drive overall coverage toward ~100%, including new tests around poller internals, HTTP operation behavior, and additional rewriteUrl error-path coverage.

Changes:

  • Added new internal unit tests for poller internals (buildCreatePoller, pollOperation, state-guard behavior) and HTTP operation helpers.
  • Extended public LRO tests to exercise additional createHttpPoller behaviors (operation-location callbacks, resolve-on-unsuccessful paths, error formatting).
  • Extended rewriteUrl tests to cover invalid base URL / relative URL resolution error handling.

Reviewed changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
sdk/core/core-lro/test/utils/utils.ts Adds shared test helpers for constructing RawResponse and operation state objects.
sdk/core/core-lro/test/public/lro.spec.ts Adds a large createHttpPoller test suite covering additional polling and error scenarios.
sdk/core/core-lro/test/internal/rewriteUrl.spec.ts Adds an additional negative test for rewriteUrl error handling.
sdk/core/core-lro/test/internal/pollerInternals.spec.ts Introduces tests for poller operation internals (deserializeState, pollOperation, initOperation).
sdk/core/core-lro/test/internal/poller-state-guard.spec.ts Adds tests for defensive “state must be initialized” guards in the poller.
sdk/core/core-lro/test/internal/pollHttpOperation.spec.ts Adds a focused test for pollHttpOperation default processResult behavior.
sdk/core/core-lro/test/internal/http-operation.spec.ts Adds broad unit tests for HTTP operation helpers (mode inference, status/error parsing, retry-after handling).
sdk/core/core-lro/test/internal/buildCreatePoller.spec.ts Adds tests for Body/ResourceLocation status handling and a polling interval path.

Comment thread sdk/core/core-lro/test/public/lro.spec.ts
Comment thread sdk/core/core-lro/test/internal/poller-state-guard.spec.ts Outdated
Comment thread sdk/core/core-lro/test/internal/poller-state-guard.spec.ts Outdated
Comment thread sdk/core/core-lro/test/internal/pollerInternals.spec.ts Outdated
Comment thread sdk/core/core-lro/test/internal/buildCreatePoller.spec.ts Outdated
- Remove brittle line numbers from test names in poller-state-guard
- Rename misleading isDone describe block in pollerInternals
- Rename setDelay test to match actual behavior in buildCreatePoller
- Use non-zero retry-after value (1) to properly exercise setDelay branch
- Run format

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
deyaaeldeen pushed a commit that referenced this pull request Apr 17, 2026
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Deyaaeldeen Almahallawi and others added 2 commits April 17, 2026 23:34
…ientHelpers tests

The find() callback already matches by policy name, so asserting
strictEqual on .name after isDefined is redundant. Also simplifies
the assertions by inlining find() into isDefined.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
- serviceClient.spec.ts: Replace weak assert.isDefined with specific
  assertions verifying Invalid Date instance for malformed DateTime string
- authorizeRequestOnTenantChallenge.spec.ts: Fix const->let for calledOnce
  variable so both if/else branches are exercised in mock

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@deyaaeldeen deyaaeldeen requested a review from timovv as a code owner April 17, 2026 23:34
Deyaaeldeen Almahallawi and others added 3 commits April 17, 2026 23:38
…m status, and retry-after

- Assert getPollingInterval callback is actually invoked (buildCreatePoller.spec.ts)
- Assert getStatusFromPollResponse callback is actually invoked (pollerInternals.spec.ts)
- Rename retry-after test to accurately describe smoke test behavior (lro.spec.ts)

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Deyaaeldeen Almahallawi and others added 11 commits April 18, 2026 02:40
- Replace weak assertions with stronger alternatives
- Remove redundant isDefined before deepEqual
- Fix misleading test name

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…tests

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…ests

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Comment thread sdk/core/core-lro/test/public/lro.spec.ts Outdated
Comment thread sdk/core/core-lro/test/public/lro.spec.ts Outdated
Comment thread sdk/core/core-lro/test/public/lro.spec.ts Outdated
Comment thread sdk/core/core-lro/test/public/lro.spec.ts
Comment thread sdk/core/core-lro/test/public/lro.spec.ts
Comment thread sdk/core/core-lro/test/internal/pollerInternals.spec.ts Outdated
Comment thread sdk/core/core-lro/test/internal/http-operation.spec.ts
Comment thread sdk/core/core-lro/test/internal/http-operation.spec.ts Outdated
Comment thread sdk/core/core-lro/test/internal/http-operation.spec.ts
Comment thread sdk/core/core-lro/test/internal/buildCreatePoller.spec.ts Outdated
Deyaaeldeen Almahallawi and others added 2 commits April 21, 2026 17:36
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…ing test

- Fix misleading 'setErrorAsResult is true' title (was actually false)
- Add state assertion to 'sets state to failed' test
- Strengthen innererror chain test to verify message concatenation
- Verify milliseconds scale in retry-after date test
- Add 'missing code' test case for getErrorFromResponse
- Replace pollCount with spy for consistency
- Shorthand property nit in buildCreatePoller test

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@deyaaeldeen deyaaeldeen requested review from a team and xirzec as code owners April 21, 2026 18:12
Deyaaeldeen Almahallawi and others added 2 commits April 21, 2026 18:12
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@deyaaeldeen deyaaeldeen requested a review from jeremymeng April 21, 2026 18:23
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@deyaaeldeen deyaaeldeen merged commit 9a7b808 into main Apr 21, 2026
13 checks passed
@deyaaeldeen deyaaeldeen deleted the deyaaeldeen/core-lro-test-coverage branch April 21, 2026 18:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants